package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(20);not null;comment:'账号'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
	Mobile   string `gorm:"type:char(11);not null;comment:'手机号'"`
	Image    string `gorm:"type:varchar(255);not null;comment:'头像'"`
	Nickname string `gorm:"type:varchar(20);not null;comment:'昵称'"`
	Tel      string `gorm:"type:varchar(20);not null;comment:'手机号'"`
}

func (u *User) GetUserById(userId int) error {
	return DB.Debug().Where(userId).Limit(1).Find(&u).Error

}

func (u *User) GetUserByAccount() error {
	return DB.Debug().Where("account =?", u.Account).Limit(1).Find(&u).Error

}

func (u *User) GetUserByMobile() error {
	return DB.Debug().Where("mobile =?", u.Mobile).Limit(1).Find(&u).Error

}
func (u *User) Create() error {
	return DB.Debug().Create(&u).Error
}

func (u *User) Update() error {
	return DB.Debug().Updates(&u).Error
}
